package com.fyl.controller;

import com.fyl.pojo.User;
import com.fyl.service.QuickService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ResponseController1 {

    @RequestMapping(value = "/res1")
    public String res1(){
        return  "forward:/index.jsp";
    }


    @RequestMapping("/res2")
    public String res2(){
        return  "redirect:/index.jsp";
    }

    //http://localhost:8080/res3
    @RequestMapping("/res3")
    public ModelAndView res3(ModelAndView modelAndView){
        //modelAndView封装模型数据和视图名
        //设置模型数据
        User user = new User();
        user.setUsername("lele");
        user.setAge(18);
        modelAndView.addObject("user", user);
        modelAndView.setViewName("/index.jsp");
        return  modelAndView;
    }

    @RequestMapping("/res4")
    @ResponseBody//告诉springmvc返回的字符串不是视图名，是以响应体方式响应的数据
    public String res4(){
        return  "hello";
    }
}
